package org.example.controller;

import org.example.entity.Room;
import org.example.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/rooms")
public class RoomController {

    @Autowired
    private RoomService roomService;

    // 获取所有房间
    @GetMapping
    public List<Room> getAllRooms() {
        return roomService.getAllRooms();
    }

    // 根据ID获取房间信息
    @GetMapping("/{id}")
    public Room getRoomById(@PathVariable Integer id) {
        return roomService.getRoomById(id);
    }

    // 添加房间
    @PostMapping
    public void addRoom(@RequestBody Room room) {
        roomService.addRoom(room);
    }

    // 更新房间信息
    @PutMapping("/{id}")
    public void updateRoom(@PathVariable Integer id, @RequestBody Room room) {
        room.setId(id);
        roomService.updateRoom(id,room);
    }

    // 删除房间
    @DeleteMapping("/{id}")
    public void deleteRoom(@PathVariable Integer id) {
        roomService.deleteRoom(id);
    }

    // 获取可用房间
    @GetMapping("/available")
    public List<Room> getAvailableRooms() {
        return roomService.getAvailableRooms();
    }
}
